<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标移入提示框</title>
    <style>
        
        ul{
            background-color: yellow;
            border: 10px;
        }
        li{
            background-color: pink;
            color: blue;
            height: 20px;
            margin: 20px 0;
        }
        .ts{
            display: none;
            position: absolute;
            align-items: center;
            height: 0;
            width: 0;
            pointer-events: none;
        }
        .tip{
            /* position: relative; */
            /* margin-left: 20px; */
            /* margin-top: 20px; */
            margin-bottom: 0;
            /* margin: 20px 0; */
            background-color: lightblue;
            color: blueviolet;
            height: 20px;
            width: 100px;
            text-align: center;
            /* display: none; */
        }
        .tip-sj{
            /* position: inherit; */
            /* bottom: -15px; */
            margin-left: 40px; 
            width: 0;
            height: 0;
            border-left: 10px solid transparent;
            border-right: 10px solid transparent;
            border-top: 10px solid lightblue;
            /* display: none; */
        }

    </style>
</head>
<body>
    <ul>
        <li>001</li>
        <li>002</li>
        <li>003</li>
        <li>004</li>
        <li>005</li>
    </ul>
    <div class="ts">
        <div class="tip">点我有惊喜</div>
        <div class="tip-sj"></div>
    </div>
</body>
</html>

<script>
    //1-获取所有的li
    var liObj = document.querySelectorAll('li')
    //2-遍历
    liObj.forEach(function(item,i){
        //3-绑定事件
        item.onmousemove = function(evt){
            var e = evt || window.event
            var divObj = document.querySelector('.ts')
            divObj.style.display = 'block'
            divObj.style.left = e.clientX -50 +'px'
            divObj.style.top = e.clientY -30+'px'
        }
        item.onmouseout = function(){
            var divObj = document.querySelector('.ts')
            divObj.style.display = 'none'
        }
    })
    
</script>

